//
//  DigitalEyeViewController.m
//  DigitalEye
//
//  Created by David Wagner on 05/07/2009.
//  Copyright Appaweek 2009. All rights reserved.
//

#import "DigitalEyeViewController.h"

@implementation DigitalEyeViewController

@synthesize imagePicker;

- (void)initImagePicker
{
	self.imagePicker = [[[UIImagePickerController alloc] init] autorelease];
	self.imagePicker.allowsImageEditing = YES;
	self.imagePicker.delegate = self;
	
	if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
	{
		self.imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
		[button setTitle:@"Take Photograph" forState:UIControlStateNormal];
	}
	else
	{
		self.imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
		[button setTitle:@"Choose Photograph" forState:UIControlStateNormal];
	}
}

- (void)viewDidLoad
{
    [super viewDidLoad];
	
	if( self.imagePicker == nil )
	{
		[self initImagePicker];
	}
}


- (void)didReceiveMemoryWarning 
{
	// Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
	
	// Release any cached data, images, etc that aren't in use.
}


- (void)viewDidUnload 
{
	// Release any retained subviews of the main view.
	// e.g. self.myOutlet = nil;
}


- (void)dealloc 
{
	self.imagePicker = nil;
	
    [super dealloc];
}


- (IBAction) takePhotograph:(id)sender
{
	[self presentModalViewController:imagePicker animated:YES];
}

- (UIImage*) scalePhoto:(UIImage*)src
{
	return src;
}

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
	UIImage * img = [info objectForKey:UIImagePickerControllerEditedImage];
	
	if(img != nil)
	{
		[imageView setImage:[self scalePhoto:img]];
	}
	
	[[picker parentViewController] dismissModalViewControllerAnimated:YES];	
}

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
	[[picker parentViewController] dismissModalViewControllerAnimated:YES];	
}
@end
